package com.androinject.test.components;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

public class InstanceCounter {
	
	private static Map<String, Integer> counters = new HashMap<String, Integer>();
	
	public static void increase(String className) {
		Integer value = counters.get(className);
		if (value == null) {
			value = new Integer(1);
		} else {
			value = new Integer(value.intValue() + 1);
		}
		counters.put(className, value);
	}
	
	public static void resetAllCounters()  {
		for (Entry<String, Integer> entry : counters.entrySet()) {
			System.out.println("InstanceCounter: setting " + entry.getKey() + " to 0");
			counters.put(entry.getKey(), new Integer(0));
		}
	}
	
	public static int getCount(String className) {
		Integer value = counters.get(className);
		if (value == null) {
			counters.put(className, new Integer(0));
			return 0;
		}
		return value.intValue();
	}
}
